Sets the calling thread's cancelability type.
1 – C Binding
#include <pthread.h>
int
pthread_setcanceltype (
int type,
int *oldtype);
2 – Arguments
type
The cancelability type to set for the calling thread. The
following are valid values:
PTHREAD_CANCEL_DEFERRED
PTHREAD_CANCEL_ASYNCHRONOUS
oldtype
Returns the previous cancelability type.
3 – Description
This routine sets the cancelability type and returns the previous
type in location oldtype.
When a thread's cancelability state is set to PTHREAD_CANCEL_
DISABLE, (see pthread_setcancelstate()), a cancelation request
cannot be delivered to that thread, even if a cancelable routine
is called or asynchronous cancelability type is enabled.
When the cancelability state is set to PTHREAD_CANCEL_ENABLE,
cancelability depends on the thread's cancelability type, as
follows:
o If the thread's cancelability type is PTHREAD_CANCEL_DEFERRED,
the thread can only receive a cancelation request at a
cancelation point (including condition waits, thread joins,
and calls to pthread_testcancel()).
o If the thread's cancelability type is PTHREAD_CANCEL_
ASYNCHRONOUS, the thread can be canceled at any point in its
execution.
When a thread is created, the default cancelability type is
PTHREAD_CANCEL_DEFERRED.
CAUTION
If the asynchronous cancelability type is set, do not call
any routine unless it is explicitly documented as "safe for
asynchronous cancelation." Note that none of the general
run-time libraries and none of the POSIX Threads libraries
are safe for asynchronous cancelation except for pthread_
setcanceltype() and pthread_setcancelstate().
Use asynchronous cancelability only when you have a compute-
bound section of code that carries no state and makes no
routine calls.
4 – Return Values
On successful completion, this routine returns the previous
cancelability type in oldtype.
If an error condition occurs, this routine returns an integer
value indicating the type of error. Possible return values are as
follows:
Return Description
0 Successful completion.
[EINVAL] The specified type is not PTHREAD_CANCEL_DEFERRED or
PTHREAD_CANCEL_AYNCHRONOUS.
5 – Associated Routines
pthread_cancel()
pthread_setcancelstate()
pthread_testcancel()